package vn.vttu.baocaocuoiki;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import vn.vttu.baocaocuoiki.NguyenHoangTrung.TrungActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {
	private EditText edtUsername;
	private EditText edtPass;
	private CheckBox chkRemember;
	
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		thamchieu();
	}
		
	public void thamchieu()
	{
		edtUsername = (EditText)findViewById(R.id.edtUsername);
		edtPass = (EditText)findViewById(R.id.edtPass);
		chkRemember = (CheckBox)findViewById(R.id.chkRemember);
	}
	
	public void btnReset(View view) {
		edtUsername.setText("");
		edtPass.setText("");
		chkRemember.setChecked(false);
	}
	
	public void btnRegister(View view) {
		Intent register = new Intent(getApplicationContext(),Register.class);
		startActivity(register);
	}

	public void btnLogin(View view) {
		//String Username = edtUsername.getText().toString().trim();
		//String Pass = edtPass.getText().toString().trim();
		//SharedPreferences share = (SharedPreferences) getSharedPreferences("TrangThai", MODE_PRIVATE);
		//Editor editor = share.edit();
		//docFile("DS_ThanhVien.txt");
		Intent i = new Intent(MainActivity.this,TrungActivity.class);
		startActivity(i);
	}
	
		public boolean docFile (String tenfile){
  		boolean bool = true;
  		java.io.FileInputStream fileInputStream = null;
  		java.io.InputStreamReader inputStreamReader = null; 
  		java.io.BufferedReader bufferedReader = null;
  		try {
     		//  B1 : Khai báo đối tượng File lưu trữ
  			fileInputStream = openFileInput(tenfile);
  			inputStreamReader = new InputStreamReader(fileInputStream);
  		    // B2 : Khai báo đối tượng đ�?c từ File lưu trữ.
  			bufferedReader = new BufferedReader(inputStreamReader);
  			String line="";
  		    // B3 : �?�?c nội dung từng dòng từ File lưu trữ.
  			while(( line= bufferedReader.readLine())!=null)
  			{
  				String[] chuoi = line.split("#");
  				if(edtUsername.getText().toString().trim() == chuoi[0] && edtPass.getText().toString().trim() == chuoi[1])
  				{
  					
   				}
  			}
  			bufferedReader.close();
  		} catch (Exception e) {
  			// TODO: handle exception
  			bool = false;
  			Toast.makeText(getApplicationContext(), "Có lỗi trong quá trình đọc File." +e.toString() , Toast.LENGTH_LONG).show();
  		}  		
  		return bool;
  	}
}
